package com.zjw.zy.heart.wechat.receiver;

import com.zjw.zy.heart.configuration.TaskPool;
import com.zjw.zy.heart.wbsocket.socket.WsMessage;
import com.zjw.zy.heart.service.IWechatService;
import com.zjw.zy.heart.utils.LogUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Component
public class WechatQueueReceiver {

    private static final String TAG = "WechatQueueReceiver";

    private IWechatService wechatService;

    @JmsListener(destination = "${spring.activemq.queue-wechat}", containerFactory = "wechatListenerContainerFactoryQueue")
    public void onReceive(WsMessage message) {
        LogUtils.d(TAG, "receive message" + message);

        TaskPool.getConcurrentPool().execute(() -> {
            onDispatchWechatMessage(message);
        });
    }

    private void onDispatchWechatMessage(WsMessage message) {
        wechatService.pushToTargetUser(message);
    }


    @Autowired
    public void setWechatService(IWechatService wechatService) {
        this.wechatService = wechatService;
    }
}
